<%--
  Created by IntelliJ IDEA.
  User: mi
  Date: 2019/5/24
  Time: 16:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="common/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="common/bootstrap/css/bootstrap.css" media="all">
    <link rel="stylesheet" type="text/css" href="common/global.css" media="all">
    <link rel="stylesheet" type="text/css" href="css/personal.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/mater.min.css">
    <script src="js/jquery2.js"></script>
    <script src="common/bootstrap/js/bootstrap.js"></script>
</head>
<body>
<div class="container-fluid">
    <table class="table  table-hover table-condensed">
        <thead>
        <tr>
            <th>员工编号</th>
            <th>员工姓名</th>
            <th>所在部门</th>
            <th>所在职位</th>
            <th>英文名</th>
            <th>肖用名</th>
            <th>性别</th>
            <th>省份证号</th>
            <th>出生日期</th>
            <th>籍贯</th>
            <th>名族</th>
            <th>政治面貌</th>
            <th>宗教信仰</th>
            <th>健康状况</th>
            <th>婚姻状况</th>
            <th>工资账号</th>
            <th>社保账号</th>
            <th>参加工作时间</th>
            <th>进入单位时间</th>
            <th>户口所在地</th>
            <th>学历</th>
            <th>职称</th>
            <th>办公电话</th>
            <th>住宅电话</th>
            <th>移动电话</th>
            <th>所属角色</th>
            <th>用户名称</th>
        </tr>
        </thead>
        <tbody id="tbody" class="table table-striped">

        </tbody>
    </table>
    <a href="toAddUser.jsp" class="btn btn-info">添加</a>
    <a class="btn btn-info">删除</a>
    <button data-toggle="modal" data-target="#myModal" class="btn btn-info">修改</button>
    <%--模态框一--%>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="updateForm">
                        <div class="form-group" hidden>
                            <label for="oldUname">老的用户名</label>
                            <input type="text" class="form-control" name="oldUname" id="oldUname">
                        </div>
                        <div class="form-group">
                            <label for="uname">用户名</label>
                            <input type="text" class="form-control" name="uname" id="uname">
                        </div>
                        <div class="form-group" hidden>
                            <label for="oldRoleName">老的角色</label>
                            <input type="text" class="form-control" id="oldRoleName" name="oldRoleName">
                        </div>
                        <div class="form-group">
                            <label for="roleName">角色</label>
                            <input type="text" class="form-control" id="roleName" name="roleName">
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-link" id="save">Save</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>

    $(function () {
        $.ajax({
            type: "get",
            url: "${pageContext.request.contextPath}/user/queryEmpAndUserAndRoleAll",
            dataType: "json",
            success: function (data) {
                $.each(data, function (index, da) {
                    var rows = "<tr onclick='updateRow(this);'>" +
                        "<th>" + da.empid + "</th>" +
                        "<th>" + da.empname + "</th>" +
                        "<th>" + da.departId + "</th>" +
                        "<th>" + da.ductId + "</th>" +
                        "<th>" + da.englishname + "</th>" +
                        "<th>" + da.nameusedbefore + "</th>" +
                        "<th>" + da.sex + "</th>" +
                        "<th>" + da.idcard + "</th>" +
                        "<th>" + da.birthday + "</th>" +
                        "<th>" + da.natives + "</th>" +
                        "<th>" + da.nation + "</th>" +
                        "<th>" + da.poleticalstatus + "</th>" +
                        "<th>" + da.religiousbelief + "</th>" +
                        "<th>" + da.healthcondition + "</th>" +
                        "<th>" + da.maritalstatus + "</th>" +
                        "<th>" + da.wagesaccount + "</th>" +
                        "<th>" + da.socialsecuritynumbers + "</th>" +
                        "<th>" + da.partworktime + "</th>" +
                        "<th>" + da.entertime + "</th>" +
                        "<th>" + da.place + "</th>" +
                        "<th>" + da.education + "</th>" +
                        "<th>" + da.jobId + "</th>" +
                        "<th>" + da.officephone + "</th>" +
                        "<th>" + da.homephone + "</th>" +
                        "<th>" + da.mobilephone + "</th>" +
                        "<th>" + da.roleName + "</th>" +
                        "<th>" + da.uname + "</th>" +
                        "</tr>";
                    $("#tbody").append(rows);
                })
            },
            error: function () {
                window.location.href = "404.jsp";
            }
        });

        $("#save").on("click", function () {
            $.ajax({
                type: "get",
                url: "user/updateUser",
                data: $("#updateForm").serialize(),
                dataType: "",
                success: function () {
                    window.location.reload();
                },
                error: function () {
                    alert("500");
                }
            });
        })

        $("a:contains('删除')").on("click", function () {
            $.ajax({
                type: "get",
                url: "user/deleteUser",
                data: $("#updateForm").serialize(),
                dataType: "",
                success: function () {
                    window.location.reload();
                },
                error: function () {
                    alert("500");
                }
            });
        })

    });

    function updateRow(obj) {
        var uname = $("#uname");
        var roleName = $("#roleName");
        var oldUname = $("#oldUname");
        var oldRoleName = $("#oldRoleName");
        uname.val(obj.lastChild.innerText);
        oldUname.val(obj.lastChild.innerText);
        var lastChilPrevious = obj.lastChild.previousSibling;
        roleName.val(lastChilPrevious.innerText);
        oldRoleName.val(lastChilPrevious.innerText);
    }
</script>
</html>
